package cs131.pa1.filter.sequential;
import java.util.List;
import java.util.Scanner;

import cs131.pa1.filter.Filter;

public class SequentialREPL {
	static String currentWorkingDirectory;

	public static void main(String[] args){		
		currentWorkingDirectory=System.getProperty("user.dir").replace("\\", Filter.FILE_SEPARATOR);
		currentWorkingDirectory.replace("/",Filter.FILE_SEPARATOR); 
		System.out.print(cs131.pa1.filter.Message.WELCOME);
		Scanner s1=new Scanner(System.in);
		System.out.print(cs131.pa1.filter.Message.NEWCOMMAND);
		String input=s1.nextLine();
		while(!"exit".equals(input)){
			List<SequentialFilter> sequentialFilters = SequentialCommandBuilder.createFiltersFromCommand(input);

			if(sequentialFilters != null){
				for (int i=1,len = sequentialFilters.size(); i< len; i++){
					sequentialFilters.get(i-1).setNextFilter(sequentialFilters.get(i));
				}
				SequentialFilter filter = sequentialFilters.get(0);
				while (filter!=null){
					filter.process();
					filter=(SequentialFilter)filter.getNext();
				}
			}

			System.out.print(cs131.pa1.filter.Message.NEWCOMMAND);
			input=s1.nextLine();
		}
		s1.close();	
		if(input.equals("exit")) {
			System.out.print(cs131.pa1.filter.Message.GOODBYE);
		}
			
	}

}
